<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
<head lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=1226">
    <meta th:name="_csrf" th:content="${_csrf.token}"/>
    <!-- 默认的header name是X-CSRF-TOKEN -->
    <meta th:name="_csrf_header" th:content="${_csrf.headerName}"/>
    <title>云商城-秒杀商品详情</title>
    <!-- 引入图标库-->
    <link href="http://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <!--bootstrap-->
    <link rel="stylesheet" th:href="@{/static/resource/css/lib/bootstrap.min.css}"/>
    <!--    引入alibaba iconfont-->
    <link rel="stylesheet" href="//at.alicdn.com/t/font_2608271_v7p87hrx9q.css">

    <!--css-->
    <link rel="stylesheet" th:href="@{/static/resource/css/reset.css}"/>
    <link rel="stylesheet" th:href="@{/static/resource/css/index.css}"/>
    <link rel="stylesheet" th:href="@{/static/resource/css/cart.css}"/>
    <link rel="stylesheet" th:href="@{/static/resource/css/home.css}"/>
    <link rel="stylesheet" th:href="@{/static/resource/css/order.css}"/>
    <link rel="stylesheet" th:href="@{/static/resource/css/common/common.css}"/>
    <link rel="stylesheet" th:href="@{/static/js/directives/css/search.css}"/>
    <link rel="stylesheet" th:href="@{/static/js/directives/css/focusImg.css}"/>
    <link rel="stylesheet" th:href="@{/static/js/directives/css/focusImgMult.css}"/>
    <link rel="stylesheet" th:href="@{/static/js/directives/css/ulBox2.css}"/>


    <!--    layui-->
    <link rel="stylesheet" th:href="@{/static/layui/css/layui.css}">

</head>

<style>
    * {
        box-sizing: border-box;
    }


    div.search {
        padding: 30px 0;
    }

    form {
        position: relative;
        width: 300px;
        margin: 0 auto;
    }

    input, button {
        border: none;
        outline: none;
    }

    input {
        width: 100%;
        height: 42px;
        padding-left: 13px;
    }

    button {
        height: 42px;
        width: 42px;
        cursor: pointer;
        position: absolute;
    }

    /*搜索框6*/
    .bar6 input {
        border: 2px solid #c5464a;
        border-radius: 5px;
        background: transparent;
        top: 0;
        right: 0;
    }

    .bar6 button {
        background: #c5464a;
        border-radius: 0 5px 5px 0;
        width: 60px;
        top: 0;
        right: 0;
    }

    .bar6 button:before {
        content: "\f002";
        font-family: FontAwesome;
        font-size: 13px;
        color: #F9F0DA;
    }

    .search input {
        height: 42px;
    }


    ul, ol {
        list-style: none;
    }

    input, button {
        outline: none;
        border: none;
    }

    a {
        text-decoration: none;
    }

    .clearfix::before,
    .clearfix::after {
        content: "";
        height: 0;
        line-height: 0;
        display: block;
        visibility: hidden;
    }

    .clearfix::after {
        clear: both;
    }

    .product li {
        float: left;
        width: 234px;
        height: 246px;
        padding: 34px 0 20px;
        z-index: 1;
        margin-left: 14px;
        margin-bottom: 35px;
        background: #fff;
        -webkit-transition: all .2s linear;
        transition: all .2s linear;
        position: relative;
    }


    .pro-img a {
        width: 100%;
        height: 100%;
    }

    .pro-img img {
        display: block;
        width: 100%;
        height: 100%;
    }

    .product li h3 {
        margin: 0 10px;
        font-size: 14px;
        font-weight: 400;
        text-align: center;
    }

    .product li h3 a {
        color: #333;
    }


    .price del {
        color: #b0b0b0;
    }


    .review a {
        color: #757575;
        display: block;
        padding: 8px 30px;
        outline: 0;
    }

    .review a span {
        display: block;
        margin-bottom: 5px;
        color: #fff;
    }

    .product li:hover {
        -webkit-box-shadow: 0 15px 30px rgba(0, 0, 0, 0.1);
        box-shadow: 0 15px 30px rgba(0, 0, 0, 0.1);
        -webkit-transform: translate3d(0, -2px, 0);
        transform: translate3d(0, -2px, 0);
    }

    .product li:hover .review {
        opacity: 1;
        height: 76px;
    }


    /*    */
    #box {
        width: 100%;
        height: 880px;
    }

    #content {
        width: 1226px;
        height: 860px;
        margin: 0 auto;
    }

    #left {
        margin-top: 3%;
        width: 500px;
        height: 410px;
        float: left;
    }

    #top {

        width: 100%;
        height: 76.8px;

    }

    #top ul li {

        float: left;
        width: 160px;
        height: 40px;
        text-align: center;
        list-style: none;
        line-height: 80px;
    }

    #top ul li a {

        text-decoration: none;
    }

    #big {
        width: 500px;
        height: 350px;
        float: left;
    }

    #small {
        width: 500px;
        height: 60px;
        float: left;
    }


    #right {
        margin-top: 3%;
        width: 550px;
        height: 650px;
        float: left;
        margin-left: 10%;
    }

    #title {
        width: 100%;
        height: 60px;
    }

    #productname {

        font-size: 20px;
        margin-top: 15px;

    }

    #price {
        margin-left: 16px;
        font-size: 20px;
        margin-top: 15px;
        color: #ff6700;
    }





    #Finally {

        width: 100%;
        height: 100px;

    }
    /* 下拉框*/

    .dropbtn {
        border: none;
        cursor: pointer;
    }

    .dropdown {
        position: relative;
        display: inline-block;
        z-index: 100;
        margin-left:25px
    }

    .dropdown-content {
        display: none;
        background-color: #f9f9f9;
        min-width: 50px;
        overflow: auto;
        box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
        z-index: 1;
    }

    .dropdown-content a {
        color: black;
        text-decoration: none;
        display: block;
    }

    .dropdown a:hover {background-color: #f1f1f1}

    .show {display:block;}
    .topbar a:hover{
        color: orange;
    }




</style>

<body>
<!-- jquery.js angular.js-->
<script th:src="@{/static/resource/lib/jquery.min.js}"></script>
<script th:src="@{/static/resource/lib/angular.js}"></script>

<!--头部工具栏-->
<div class="topbar">
    <div class="container">
        <div class="topbar_nav fl">
            <ul>
                <li><a th:href="@{/web/index/}">首页</a></li>
                <li><a th:href="@{/web/couponsActivity/toCouponsActivity}">领劵中心</a></li>
                <li><a th:href="@{/web/seckill/toSearchSeckillPage}">秒杀</a></li>
                <li><a href="https://github.com/youzhengjie9/cloud-mall">项目链接</a></li>
            </ul>
        </div>
        <div class="topbar_cart fr">
            <a href="/web/cart/tocart">购物车</a>
        </div>

        <div class="topbar_cart fr">
            <a href="/web/order/toOrderPage">我的订单</a>
        </div>
        <div class="topbar_cart fr">
            <a href="/web/seckill/toSeckillSuccessList">秒杀成功订单</a>
        </div>
        <div class="topbar_info fr" style="width:220px">
            <form name="logoutform" th:action="@{/web/logout/logout}" method="post"></form>
            <a class="nav-link" th:href="@{/web/register/toregister}">注册</a>
            <a class="nav-link" sec:authorize="isAnonymous()" th:href="@{/web/login/toLoginPage}">登录</a>
            <a sec:authorize="isAuthenticated()" class="nav-link dropbtn" onclick="myFunction()">[[${username}]]</a>
            <a href="#" onclick="kefu(1)">人工客服</a>
            <div class="dropdown">
                <div id="myDropdown" class="dropdown-content" style="width: 120px;height: 70px">
                    <a th:href="@{/web/center/toBaseInfo}" style="width: 100px;height: 30px;">个人中心</a>
                    <a href="javascript:document.logoutform.submit();" style="width: 100px;height: 30px;">退出登录</a>
                </div>
            </div>
        </div>
    </div>
</div>


<!--  秒杀商品详情-->
<div id="box">


    <div id="content">

        <div id="top">


        </div>


        <div id="left">

            <div id="big">

                <img th:src="${seckill.img}" style="width: 500px;height: 350px">

            </div>

<!--            缩略图待实现-->
            <div id="small">


            </div>
        </div>


        <div id="right">


            <div id="title">

                <div id="productname">
                    购买[[${seckill.seckillName}]]
                    <span id="price">
  		 				[[${seckill.price}]]元
  		 			</span>
                    <div th:if="${state==0}" class="colockbox" id="colockbox1">
                        倒计时：
                        <span class="day">0</span>
                        <span>天</span>
                        <span class="hour">00</span>
                        <span>小时</span>
                        <span class="minute">00</span>
                        <span>分</span>
                        <span class="second">00</span>
                        <span>秒</span>
                    </div>
                    <div th:if="${state==1}" class="colockbox">
                        秒杀已开始
                    </div>

                </div>


            </div>
            <span style="color: red;">温馨提示：该产品为秒杀活动产品,至于是否购买成功，以最终下单为准哦，请尽快结算!</span>


            <div id="Finally">
                <br/>
                <br/>
                <br/>
                <button id="btn1" th:if="${state==0}" class="btn btn-warning disabled" style="color: black">开始秒杀</button>

                <button th:if="${state==1}" th:onclick="miaosha([[${seckill.seckillId}]])" class="btn btn-warning" style="color: black">开始秒杀</button>


            </div>


        </div>

    </div>

</div>

<!---->


<!-- buy-choose-box END -->
<hr/>


<!--footer-->
<footer class="footer">
    <div class="container">
        <div class="footer_service">
            <ul class="clearfix">
                <li><a href="">1小时快修服务</a></li>
                <li><a href="">7天无理由退货</a></li>
                <li><a href="">30天免费换货</a></li>
                <li><a href="">满200元包邮</a></li>
                <li><a href="">520余家售后网点</a></li>
            </ul>
        </div>

        <div class="footer_link clearfix">
            <dl>
                <dt>帮助中心</dt>
                <dd>购物指南</dd>
                <dd>支付方式</dd>
                <dd>配送方式</dd>
            </dl>
            <dl>
                <dt>帮助中心</dt>
                <dd>购物指南</dd>
                <dd>支付方式</dd>
                <dd>配送方式</dd>
            </dl>
            <dl>
                <dt>帮助中心</dt>
                <dd>购物指南</dd>
                <dd>支付方式</dd>
                <dd>配送方式</dd>
            </dl>
            <dl>
                <dt>帮助中心</dt>
                <dd>购物指南</dd>
                <dd>支付方式</dd>
                <dd>配送方式</dd>
            </dl>
            <dl>
                <dt>帮助中心</dt>
                <dd>购物指南</dd>
                <dd>支付方式</dd>
                <dd>配送方式</dd>
            </dl>
            <dl>
                <dt>帮助中心</dt>
                <dd>购物指南</dd>
                <dd>支付方式</dd>
                <dd>配送方式</dd>
            </dl>

            <div class="footer_contact">
                <p class="phone">18420163207</p>

                <p><span style="">周一至周日 8:00-18:00</span>
                    <span style="display:none;">2月7日至13日服务时间 7:00-18:00</span><br>（仅收市话费）</p>
                <a rel="nofollow" class="btn btn-primary btn-small" href="#">24小时在线客服</a>
            </div>
        </div>

    </div>

    <div class="footer_site">
        <div class="container">
            <div class="cart_log">
                <a href="" title="云商城"></a>
            </div>
            <div>
                <p>云商城项目由本人自己完成,如有不足,请指正！</p>
            </div>
        </div>
    </div>
</footer>


</body>


<script th:inline="javascript">

    var starttime=[[${seckill.startTime}]];

    var seckillid=[[${seckill.seckillId}]];

    //秒杀倒计时
    $(function(){
        let s= [[${state}]];
        if(s==0){ //活动没开始才倒计时
            countDown(starttime,"#colockbox1");
        }
    });
    function countDown(time,id){
        var day_elem = $(id).find('.day');
        var hour_elem = $(id).find('.hour');
        var minute_elem = $(id).find('.minute');
        var second_elem = $(id).find('.second');

//if(typeof end_time == "string")
        var end_time = new Date(time).getTime(),//月份是实际月份-1
            sys_second = (end_time-new Date().getTime())/1000;
        var timer = setInterval(function(){
            if (sys_second > 1) {
                sys_second -= 1;
                var day = Math.floor((sys_second / 3600) / 24);
                var hour = Math.floor((sys_second / 3600) % 24);
                var minute = Math.floor((sys_second / 60) % 60);
                var second = Math.floor(sys_second % 60);
                day_elem && $(day_elem).text(day);//计算天
                $(hour_elem).text(hour<10?"0"+hour:hour);//计算小时
                $(minute_elem).text(minute<10?"0"+minute:minute);//计算分钟
                $(second_elem).text(second<10?"0"+second:second);//计算秒杀
            } else {
                clearInterval(timer);
                let b=document.getElementById('btn1');
                b.setAttribute("onclick","miaosha("+seckillid+")");
                b.classList.remove('disabled');
                let c=document.getElementById('colockbox1');
                c.innerHTML='秒杀已开始'
            }
        }, 1000);
    }




    // 获取<meta>标签中封装的_csrf信息 ,否则会请求403
    var token = $("meta[name='_csrf']").attr("content");
    var header = $("meta[name='_csrf_header']").attr("content");
    var headers = {"X-CSRF-TOKEN": token}

    //js提交表单
    function submitData() {
        document.getElementById("form").submit();
    }


    /* 点击按钮，下拉菜单在 显示/隐藏 之间切换 */
    function myFunction() {
        document.getElementById("myDropdown").classList.toggle("show");
    }

    // 点击下拉菜单意外区域隐藏
    window.onclick = function(event) {
        if (!event.target.matches('.dropbtn')) {

            var dropdowns = document.getElementsByClassName("dropdown-content");
            var i;
            for (i = 0; i < dropdowns.length; i++) {
                var openDropdown = dropdowns[i];
                if (openDropdown.classList.contains('show')) {
                    openDropdown.classList.remove('show');
                }
            }
        }
    }

    //开始秒杀
    function miaosha(secid) {

        $.ajax({
            url: "/web/seckill/doSeckill/"+secid,
            data: {},
            type: "GET",
            success: function (data) {
                if(data.success==true){
                    alert(data.msg)
                    window.location.href='/web/seckill/toSeckillSuccessList';
                }else {
                    alert(data.msg)
                }
            },
            error: function () {
                alert('秒杀异常,请重试')
            }

        })


    }


    function kefu(e) {
        $.ajax({
            url:'/web/chat/HasGotoKefu',
            dataType:'json',
            type:'get',
            success:function(result){

                if(result==true){
                    window.location.href='http://localhost:5677/chat/toChat';
                }else {
                    alert('当前咨询人数过多,客服都忙不过来了,请等会儿再咨询！')
                }

            },
            error:function () {
                alert('您可能还没有登录,请登录!')
            }
        })

    }


</script>


</html>